// pages/subscribe/subscribe.js
import user from '../../utils/user.js'
import {
    getsubscribeproductapi
} from '../api/personalMsg.js'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        serviceList: [{
                label: '发薪',
                value: '0',
                isselect: false
            },
            {
                label: '投保',
                value: '1',
                isselect: false
            },
            {
                label: '电子签',
                value: '2',
                isselect: false
            },
        ],
        userName: "",
        phone: "",
        companyName: "",
        position: "",
    },
    onChangeSelect(e) {
        console.log(e.currentTarget.dataset.i);
        this.data.serviceList.forEach((ele, i) => {
            if (i === e.currentTarget.dataset.i) {
                ele.isselect = true
            } else
                ele.isselect = false
        })
        this.setData({
            serviceList: this.data.serviceList
        })
    },
    async onSubmit() {
        let value = ''
        this.data.serviceList.forEach((ele, i) => {
            if (ele.isselect) {
                value = ele.value
            }
        })
        if (!value) {
            wx.showToast({
                title: '请选择意向功能',
                icon: 'none'
            })
            return
        } else {
            let res = await getsubscribeproductapi({
                userName: this.data.userName,
                companyName: this.data.companyName,
                phone: this.data.phone,
                position: this.data.position,
                productType: value
            })
            wx.showToast({
                title: '预约成功',
                icon: 'none'
            })
            wx.navigateBack()
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        user.waitLogin().then(() => {
            this.setData({
                userName: user.userName,
                companyName: user.companyName,
                position: user.position,
                phone: user.phoneNum
            })
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})